For each expedition, a birdlasser csv file with all the species recorded is exported by the observer and sent to me (Raf). I keep track of all the files received in the metadata.xlsx file. In particular, I make a list of all surveys done. A survey is a 1 hours (non-stop) recording of all species encountered. From the raw csv exported file, I note :
start_timeend_timeobserver K (Kirao), J (Juma), D (Daniel)protocol_ok whether the data are properly recorded,gap_min duration of the survey where bird were not recorded (often because of rain).Here, we read this file as table and add computed variable:
start_hour (start time rounded to the closer hour)duration (end-start-gaps) and create an surveyID an unique identifier per surveyproject.root = 'C:/Users/rnussba1/OneDrive/ARK/ARK - Science/04. Geolocator'
surveys <- read_excel(paste(project.root,"4-Data/Initial survey/metadata.xlsx",sep="/"), sheet=2) %>%
mutate(
start_time = parse_time(format(start_time,'%H:%M')),
first_sighting = parse_time(format(first_sighting,'%H:%M')),
last_sighting = parse_time(format(last_sighting,'%H:%M')),
end_time = parse_time(format(end_time,'%H:%M')),
gap_min = ifelse( is.na(gap_min), 0, as.integer(format(gap_min,'%M'))),
start_hour = parse_time(format(round(as.POSIXct(start_time, format="%H:%M:%S"), units="hours"),'%H:%M')),
duration = difftime(end_time,start_hour)-gap_min,
ID = paste( format(date), str_replace(start_hour,':00:00','00') , observer, sep = '_' )
) %>%
filter(ifelse(is.na(protocol_ok), TRUE, FALSE))
The current dataset includes 13 surveys, spanning from 2020-05-19 to 2020-08-30, totalizing 264 hours.
Based on the metadata of each survey loaded in the previous section, we can now create the database including all sightings (i.e.Ā individual observation) and associated survey information.
d <- surveys %>%
pmap_dfr(function(...) {
s <- tibble(...)
read_csv(paste(project.root,'/4-Data/Initial survey/', s$filename,'.csv',sep=""),
col_types = cols_only(
`Species primary name` = col_character(),
`BirdMAP ID` = col_double(),
Date = col_date(format = ""),
Time = col_time(format = ""),
Latitude = col_double(),
Longitude = col_double(),
Notes = col_character()
)
) %>%
filter(Date == s$date, s$start_time <= Time, s$end_time >= Time ) %>%
mutate(filename = s$filename,
observer = s$observer,
start_hour = s$start_hour,
duration = s$duration,
start_time = s$start_time,
end_time = s$end_time,
gap_min = s$gap_min,
notes_survey = s$notes,
survey_ID = s$ID
) %>%
arrange(Time)
}) %>% group_by(survey_ID) %>%
mutate(nb_sightings = n_distinct (`Species primary name`),
nb_MK = sum(`BirdMAP ID`==400))
datatable(d, filter = "top", extensions = 'Buttons', options = list(dom = 'Bfrtip', buttons = c('csv')), rownames = FALSE, class = "compact")
Based on the observations, we can provide more information on each surveys, such as number of species seen nb_sightings, the number of Mangrove Kingfisher seen nb_MK.
d %>% summarise(Date = median(Date),
Time = median(Time),
Latitude = mean(Latitude),
Longitude = mean(Longitude),
observer = first(observer),
duration = median(duration),
Date = median(Date),
Date = median(Date),
nb_MK = median(nb_MK),
nb_sightings = median(nb_sightings),
.groups="drop"
)%>%
datatable(filter = "top", extensions = 'Buttons', options = list(dom = 'Bfrtip', buttons = c('csv')), rownames = FALSE, class = "compact")
# Map surveys track and MK locations
m <- leaflet(width = "100%") %>%
addProviderTiles("MapBox", options = providerTileOptions(
id = "mapbox.satellite",
accessToken = 'pk.eyJ1IjoicmFmbnVzcyIsImEiOiIzMVE1dnc0In0.3FNMKIlQ_afYktqki-6m0g')) %>%
addFullscreenControl()
factpal <- colorFactor(brewer.pal(12, 'Paired'), as.factor(d$survey_ID))
for (s in unique(d$survey_ID)){
m <- addPolylines(m, data=d %>%
filter(survey_ID==s) %>%
mutate(label = paste(sep = "",
"<b>Date:</b> ", Date, ' ', start_hour,'<br>',
"<b>Observer:</b> ", observer,'<br>',
"<b>Duration</b>: ", duration, ifelse(gap_min>0,paste(sep='',' (',gap_min,'of gap)'),' min'),'<br>',
"<b>Nb of sightings</b>: ", nb_sightings,'<br>',
"<b>Nb of MK</b>: ", nb_MK,'<br>',
"<b>Note</b>: ", notes_survey
)),
lng = ~Longitude, lat = ~Latitude , group = ~Date, color=~factpal(survey_ID), popup = ~label)
}
m <- addCircleMarkers(m, data = d %>%
mutate(label = paste(sep = "",
"<b>Species:</b> ", `Species primary name`,'<br>',
"<b>Date:</b> ", Date, ' ', Time,'<br>',
"<b>Observer:</b> ", observer,'<br>',
"<b>Note</b>: ", Notes
)),
lng = ~Longitude, lat = ~Latitude, popup = ~label,
radius = ~ifelse(`BirdMAP ID`==400, 10, 6),
stroke = FALSE,
fillOpacity = ~ifelse(`BirdMAP ID`==400, 1, 0.8),
color = ~factpal(survey_ID),
group = ~Date)
m <- m %>% addLayersControl(
overlayGroups = d$Date,
options = layersControlOptions(collapsed = FALSE)
)
m
## All MK sightings
dMK <- read_csv(paste(project.root,'/4-Data/Initial survey/BL_EVENT_mangrovekingfisherproj.csv',sep=""),
col_types = cols_only(
date = col_date(format = ""),
time = col_time(format = ""),
locationLat = col_double(),
locationLon = col_double(),
lead = col_character()
)) %>%
mutate(lead = gsub("\\@.*","",lead))
datatable(dMK, filter = "top", extensions = 'Buttons', options = list(dom = 'Bfrtip', buttons = c('csv')), rownames = FALSE, class = "compact")
m <- leaflet(width = "100%") %>%
addProviderTiles("MapBox", options = providerTileOptions(
id = "mapbox.satellite",
accessToken = 'pk.eyJ1IjoicmFmbnVzcyIsImEiOiIzMVE1dnc0In0.3FNMKIlQ_afYktqki-6m0g')) %>%
addFullscreenControl()
factpal <- colorFactor(brewer.pal(12, 'Paired'), as.factor(d$survey_ID))
for (s in unique(d$survey_ID)){
m <- addPolylines(m, data=d %>%
filter(survey_ID==s),
lng = ~Longitude, lat = ~Latitude , group = ~Date, color='black')
}
m <- addMarkers(m, data = d %>%
filter(`BirdMAP ID`==400) %>%
mutate(label = paste(sep = "",
"<b>Date:</b> ", Date, ' ', Time,'<br>',
"<b>Observer:</b> ", observer,'<br>',
"<b>Note</b>: ", Notes
)),
lng = ~Longitude, lat = ~Latitude, popup = ~label,
group = 'from surveys'
)
m <- addMarkers(m, data = dMK %>%
mutate(label = paste(sep = "",
"<b>Date:</b> ", date, ' ', time,'<br>',
"<b>Observer:</b> ", lead,'<br>'
)),
lng = ~locationLon, lat = ~locationLat, popup = ~label,
group = 'from KBM',
clusterOptions = markerClusterOptions()
)
m <- m %>% addLayersControl(
overlayGroups = c('from KBM','from surveys'),
options = layersControlOptions(collapsed = FALSE)
)
m
## Bird diversity
d %>%
group_by(`Species primary name`) %>%
filter(`Species primary name`!= 'Unidentified') %>%
summarise(
n = n(),
occurance = n/length(unique(d$survey_ID)),
avgtime = parse_time(format(mean(as.POSIXct(Time, format="%H:%M:%S"))), format="%Y-%M-%D %H:%M:%S"),
groups = "drop"
) %>%
arrange(desc(n)) %>%
datatable( filter = "top", extensions = 'Buttons', options = list(dom = 'Bfrtip', buttons = c('csv')), rownames = FALSE, class = "compact")
## `summarise()` ungrouping output (override with `.groups` argument)